from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils.timezone import now

from comment.form import CommentForm
from django.http.response import HttpResponse


# Create your views here.

def comment(request):
    return_url=request.environ.get('HTTP_REFERER',reverse('index'))
    if not request.user.username:
        return HttpResponse('请先登录，再评论')
    valid_data=dict()
    valid_data['comment_content']=request.POST['comment_content']
    valid_data['comment_movie']=request.POST['movie']
    valid_data['comment_person']=request.POST['user']
    valid_data['comment_date']=now()
    commentform=CommentForm(valid_data)
    if commentform.is_valid():
        commentform.save()
        return redirect(return_url)
    else:
        return redirect(return_url)










